﻿using AutoUnitTest.Common;
using System;
using NUnit.Framework;

namespace AutoUnitTest.Tests
{
    public class CsCodeEvaluatorTest
    {
        [Test]
        public void EvalTest()
        {
            string bodyExpr = "int x = 2; int y = 3;";
            string returnExpr = "x + y";

            object result = CsCodeEvaluator.Eval(returnExpr, bodyExpr);

            Assert.AreEqual(result,5);
        }

        [Test]
        public void EvalTest2()
        {
            string bodyExpr = "int x = 5;";
            string returnExpr = "x < 10";

            object result = CsCodeEvaluator.Eval(returnExpr, bodyExpr);

            Assert.AreEqual(result, true);
        }

        [Test]
        public void FindParameterForFalseCondtitionTest()
        {
            int i = 0;
            bool found = false;
            while (!found)
            {
                string expr = "int x = " + i + ";";
                found = !(bool)CsCodeEvaluator.Eval("x < 10", expr);
                i++;
            }
            Assert.AreEqual(i, 11);
        }
    }
}
